package anno

import (
	"fmt"
	"os"
	"wails/cmds/maketools"

	"gitee.com/zhongguo168a/gocodes/myx/logx"
	"github.com/codeskyblue/go-sh"
	"github.com/spf13/cobra"
)

func init() {
	startCmd := &cobra.Command{
		Use: "anno",
		Run: func(cmd *cobra.Command, args []string) {
			client()
		},
	}

	maketools.RootCmd.AddCommand(startCmd)
}

var schemaPath = "/mnt/d/projects/yxeditor/codes/wails/schema"
var serverPath = "/mnt/d/projects/yxeditor/codes/wails"
var clientPath = "/mnt/d/projects/yxeditor/codes/client"
var gamePath = "/mnt/d/projects/yxeditor/codes/G25.1/client-cocos"

func client() {
	rsync()
}

func rsync() {
	cmd := sh.NewSession()
	cmd.ShowCMD = true
	var err error

	err = cmd.Command("/bin/sh", "-c",
		fmt.Sprintf(`anno run -p %v`, schemaPath)).Run()
	if err != nil {
		logx.Error(err)
	}
	os.MkdirAll(clientPath+"/assets/generate", os.ModePerm)

	{
		err = cmd.Command("/bin/sh", "-c",
			fmt.Sprintf(`rsync -avr %v %v`,
				serverPath+"/generate/schema_export/",
				clientPath+"/assets/resources/project",
			)).Run()
		if err != nil {
			logx.Error(err)
		}
		err = cmd.Command("/bin/sh", "-c",
			fmt.Sprintf(`rsync -avr %v %v`,
				serverPath+"/generate/schema_export/",
				gamePath+"/assets/resources/project",
			)).Run()
		if err != nil {
			logx.Error(err)
		}

		err = cmd.Command("/bin/sh", "-c",
			fmt.Sprintf(`rsync -avr %v %v`,
				serverPath+"/generate/schema_ts/",
				clientPath+"/assets/core/generate",
			)).Run()
		if err != nil {
			logx.Error(err)
		}

		err = cmd.Command("/bin/sh", "-c",
			fmt.Sprintf(`rsync -avr %v %v`,
				serverPath+"/generate/cache_ts/",
				clientPath+"/assets/core/generate/cache_ts",
			)).Run()
		if err != nil {
			logx.Error(err)
		}
	}
}
